package com.yenlien.traceyun.webase.config;

import java.sql.SQLException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.alibaba.druid.filter.config.ConfigTools;
import com.alibaba.druid.pool.DruidDataSource;


/**
 * 　 * @author wangy
 * 　 * @date 2020年2月28日
 * 　 * @version 1.0
 * 　 * Description:启用阿里druid数据源
 */

//@EnableConfigurationProperties(DataSourceProperties.class)
//@Configuration
public class DbConfiguration {

    @Autowired
    private DataSourceProperties dbp;

    @Bean("datasource")
    public DruidDataSource dataSource() throws SQLException {
        DruidDataSource ds = new DruidDataSource();
        ds.setFilters("config,stat");
        ds.setDriverClassName(dbp.getDriverClassName());
        ds.setPassword(dbp.getPassword());
        ds.setUrl(dbp.getUrl());
        ds.setConnectionProperties("config.decrypt=true");
        ds.setUsername(dbp.getUsername());
        ds.setInitialSize(3);
        ds.setMaxActive(15);
        ds.setTimeBetweenEvictionRunsMillis(60000);
        ds.setMinEvictableIdleTimeMillis(120000);
        return ds;
    }

    public static void main(String[] args) throws Exception {
        System.out.println(ConfigTools.encrypt("123123"));
    }

}
